<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleleaf.org">
<head th:insert="base">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form" action="" method="post" lay-filter = "editObj">
            <input type="hidden" name="id"/>
            <div class="layui-form-item">
                <label for="switchCode" class="layui-form-label">
                    道岔编号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="switchCode" name="switchCode" minlength="3" readonly maxlength="20" lay-verify="range"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="repairLevel" class="layui-form-label">
                    检修级别
                </label>
                <div class="layui-input-inline">
                    <select id="repairLevel" name="repairLevel" class="valid" lay-verify="required">
                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="repairPlace" class="layui-form-label">
                    检修部位
                </label>
                <div class="layui-input-inline">
                    <select id="repairPlace" name="repairPlace" class="valid" readonly lay-verify="required">
                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label for="closeTime" class="layui-form-label">截止时间</label>
                <div class="layui-input-inline">
                    <input class="layui-input" readonly  autocomplete="off" placeholder="截止时间" id="closeTime">
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label for="finishTime" class="layui-form-label">完成日期</label>
                <div class="layui-input-inline">
                    <input class="layui-input" readonly  autocomplete="off" placeholder="完成日期" id="finishTime">
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label for="remark" class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" id="remark" name="remark" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="edit" lay-submit="">
                    确认修改
                </button>
            </div>
        </form>
    </div>
</div>
<script th:inline="javascript">
    layui.use(['form','jquery','validate','tool','enums','laydate'], function(){
        var form = layui.form;
        var $ = layui.jquery;
        var validate = layui.validate;
        var tool = layui.tool;
        var baseUrl = "/back/repairTask";
        var enums = layui.enums;
        var laydate = layui.laydate;
        var repairTask = [[${repairTask}]];
        init_form();


        /**
         * 初始化页面
         */
        function init_form() {
            laydate.render({
                elem: '#closeTime'
                ,type: 'datetime'
            });
            laydate.render({
                elem: '#finishTime'
                ,type: 'datetime'
            });
            enums.createSelectByEnum('repairPlace','EnumDeviceType',['3','4'],null,'请选择检修部位');
            enums.createSelectByEnum('repairLevel','EnumRepairLevel',null,null,'请选择检修级别');
            form.render();//重新渲染
            form.val('editObj',{
                "id":repairTask.id
                ,"switchCode":repairTask.switchCode
                ,"repairPlace":repairTask.repairPlace
                ,"repairLevel":repairTask.repairLevel
                ,"remark":repairTask.remark
            });
        }

        //添加表单校验
        form.verify(validate);

        //监听提交
        form.on('submit(edit)', function(data){
            data.field.closeTimeStr = $("#closeTime").val().trim();
            data.field.finishTimeStr = $("#finishTime").val().trim();
            var res = tool.submit(baseUrl + '/edit',data.field);
            if(res.code == return_200){
                layer.msg(res.msg, {
                        icon: msg.success,
                        time: 2000
                    },
                    function(){
                        xadmin.father_reload();
                    }
                );
            }else {
                layer.msg(res.msg, {
                        icon: msg.error,
                        time: 2000
                    },
                    function(){
                        xadmin.father_reload();
                    }
                );
            }
            return false;
        });

    });
</script>
</body>
</html>